package kr.bos;

import android.app.Activity;
import android.content.Context;
import android.view.View;
import android.view.inputmethod.InputMethodManager;

/**
 * 하단 컨트롤바(싱글톤)
 * @author baek - bispro@uracle.co.kr
 * @date 2011. 12. 29.
 */
public class ControllerBottom {
	private static ControllerBottom ctrl = null;
	
	private Activity mActivity = null; 
	private boolean isVisible = false;
	
	private ControllerBottom(Activity act) {
		mActivity = act;
	}
	public static ControllerBottom getInstance(Activity act) {
		if(ctrl == null) {
			ctrl = new ControllerBottom(act);
		}
		//업데이트
		ctrl.mActivity = act;
		return ctrl;
	}

	
	/**
	 * 컨트롤바 보이는지 여부
	 * @return
	 */
	public boolean isVisible() {
		return isVisible;
	}
	public void setVisible(boolean b) {
		updateVisible(b);
		isVisible = b;
	}
	public void updateVisible(boolean isVisible) {
		if(isVisible) {
			mActivity.findViewById(R.id.control_lin_outer).setVisibility(View.VISIBLE);
			mActivity.findViewById(R.id.control_ed_txt_1).clearFocus();
		}else {
			mActivity.findViewById(R.id.control_lin_outer).setVisibility(View.GONE);
			try {
				InputMethodManager imm=(InputMethodManager)mActivity.getSystemService(Context.INPUT_METHOD_SERVICE);
				imm.hideSoftInputFromWindow(mActivity.findViewById(R.id.control_ed_txt_1).getWindowToken(), 0);
			}catch(Exception e) {
				e.printStackTrace();
			}
		}
	}
	
}
